package br.com.framework.apresentacao.datamodel;

import java.util.List;

import org.primefaces.model.LazyDataModel;

import br.com.framework.persistencia.model.BaseEntity;

/**
 * @author Cleber
 *
 * @param <ID>
 * @param <E>
 */
public abstract class LazyEntityDataModel<E extends BaseEntity> extends LazyDataModel<E> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected List<E> entityList;
	
	/**
	 * @param eList
	 * @param negocio
	 */
	public LazyEntityDataModel(List<E> eList) {
		this.entityList = eList;
	}

	@Override
	public E getRowData(String rowKey) {
		for (E entity : entityList) {
			if (entity.getId().toString().equals(rowKey))
				return entity;
		}
		return null;
	}

	@Override
	public Object getRowKey(E entity) {
		return entity.getId();
	}

}